re-type the number for this INPUT
statement.
INPUT
StatementsOften a program needs several values from the user. There are several ways this can be done. A good way is to prompt and input the values one by one.
The following program calculates the cost of a phone call. The user enters the number of minutes of the call and the cost per minute.
' Cost of a phone call ' PRINT "Enter number of minutes" INPUT MINUTES PRINT "Enter cents per minute" INPUT RATE PRINT "Cost of the call in dollars:", MINUTES*RATE/100 END
Blank lines have been put in the program to make its operation more clear. The blank lines are just skipped (like comments) when the program runs.
When this program is run,
the first PRINT
statement
will prompt the user.
Then the first INPUT
statement
will get a number from the user and put it in MINUTES:
Enter number of minutes ? 23
Now the next PRINT
statement will prompt the user
and the next INPUT
statement will get the value and
put it in RATE:
Enter number of minutes ? 23 Enter cents per minute ? 10
Finally the last PRINT
statement will perform the
calculation using the numbers in the two variables,
and print the result to the screen:
Enter number of minutes ? 23 Enter cents per minute ? 10 Cost of the call in dollars: 2.30
Write a program that asks the user for the number of kilowatt-hours of electricity used and asks for the cost in dollars of each kilowatt-hour. The program will calculate the cost of the electricity.